package com.mrjy.maintain.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mrjy.common.entity.SchoolInfo;
import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.maintain.bo.ISchoolInfoBo;
import com.mrjy.maintain.dto.SchoolInfoDTO;

@Controller
@RequestMapping("maintain/schoolInfo")
public class SchoolInfoController{
	@Resource
	private ISchoolInfoBo schoolInfoBo;
	
	/**
	 * 显示学校信息
	 * @return
	 */
	@RequestMapping("/queryPage")
	@ResponseBody
	public Object queryPage(SchoolInfoDTO dto) {
		return schoolInfoBo.queryPage(dto);
	}
	/**
	 * 添加学校
	 * @return
	 */
	@RequestMapping("/addSchoolInfo")
	@ResponseBody
	public Object insert(SchoolInfoDTO dto){
		return schoolInfoBo.txInsert(dto);
	}
	/**
	 * 根据ID查询
	 * @return
	 */
	@RequestMapping("/queryById")
	@ResponseBody
	public Object queryById(int id) {
		return schoolInfoBo.queryById(id);
	}
	/**
	 * 修改
	 * @param userInfo
	 * @return
	 */
	@RequestMapping("/updateById")
	@ResponseBody
	public Object updateById(SchoolInfoDTO dto) {		
		return schoolInfoBo.txUpdateById(dto);
	}
	
	/**
	 * 删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("/deleteByIds")
	@ResponseBody
	public Object deleteByIds(int[] ids) {		
		return schoolInfoBo.deleteByIds(ids);
	}
	/**
	 * 禁用、起用
	 * @param ids
	 * @return
	 */
	@RequestMapping("/updateDisableFlag")
	@ResponseBody
	public Object updateDisableFlag(SchoolInfo schoolInfo) {		
		return schoolInfoBo.txUpdateDisableFlag(schoolInfo);
	}
	
	/**
	 * 通过推广码查询其是否是合作学校
	 * @param recommendCode 推荐码
	 * @return
	 */
	@RequestMapping("/isSchoolByRecommendCode")
	@ResponseBody
	public Object isSchoolByRecommendCode(String recommendCode,HttpSession session) {
		UserInfo info = ((UserInfo) session.getAttribute(GlobalConstant.USER_INFO));
		@SuppressWarnings("unchecked")
		Map<String, Object> map = (Map<String, Object>) schoolInfoBo.txQuerySchoolByRecommendCode(recommendCode,info.getId());
		if((int)map.get("err_code") == 0){
			SchoolInfo schoolInfo = (SchoolInfo) map.get("info");
			info.setBelongSchoolId(schoolInfo.getId());
			info.setSchoolName(schoolInfo.getSchoolName());
			session.setAttribute(GlobalConstant.USER_INFO,info);
		}else{
			info.setBelongSchoolId(null);
			info.setSchoolName(null);
			session.setAttribute(GlobalConstant.USER_INFO,info);
		}
		return map;
	}
	
	/**
	 * 导出学校信息
	 */
	@RequestMapping("/exportSchoolInfoBack")
	@ResponseBody
	public Object exportSchoolInfoBack(HttpServletResponse response , SchoolInfoDTO dto) {
		return schoolInfoBo.exportSchoolInfoBack(response ,dto);
	}
	
	/**
	 * 通过手机号码检查其角色
	 * @param mobilePhone 手机号码
	 * @return
	 */
	@RequestMapping("/checkRoleByMobilePhone")
	@ResponseBody
	public Object checkRoleByMobilePhone(String mobilePhone) {
		return schoolInfoBo.checkRoleByMobilePhone(mobilePhone);
	}
	
	/**
	 * 微信1.6.8
	 * 渲染 家长大学页  
	 * 传sortType free-免费课程  conversation-交流  support-明师支持
	 * @param dto
	 * @return
	 */
	@RequestMapping("/drawSchool")
	@ResponseBody
	public Object drawSchool(SchoolInfoDTO dto,HttpSession session) {
		return schoolInfoBo.drawSchool(dto,session);
	}
	
	/**
	 * 家园-学校入口
	 * 查询用户所属学校
	 * @param schoolId
	 * @return
	 */
	@RequestMapping("/extrance")
	@ResponseBody
	public Object extrance(Integer schoolId,HttpSession session) {
		return schoolInfoBo.extrance(schoolId,session);
	}
	
	/**
	 * 家园-学校入口
	 * 查询用户所属学校的相关信息
	 * @param schoolId
	 * @return
	 */
	@RequestMapping("/querySchoolByid")
	@ResponseBody
	public Object querySchoolByid(Integer schoolId,HttpSession session) {
		return schoolInfoBo.querySchoolByid(schoolId,session); 
	}
	
	@RequestMapping("/countTopicPageByInfo")
	@ResponseBody
	public Object countTopicPageByInfo(HttpSession session, Integer videoTypeId){
		return schoolInfoBo.countTopicPageByInfo(session, videoTypeId);
		
	}
	
	
	
}
